package com.csnf.controller;


import csnf.com.entity.*;
import com.csnf.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController

@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;
    @PostMapping("/login")
    public ResponseObject login(@RequestBody Admin admin){
        int loginFlag = adminService.login(admin);
        if(loginFlag==1){
            return ResponseObject.success("success");
        }else{
            return ResponseObject.success("error");
        }
    }
    @RequestMapping("/selectAll")
    public ResponseObject selectAll(){
        ArrayList<Merchant> merchantArrayList = adminService.selectAll();
        if (merchantArrayList.size()>0){
            return ResponseObject.success("查询成功",merchantArrayList);
        }else{
            return ResponseObject.success("数据为空");
        }
    }
    @RequestMapping("/selectMerchantByIsExamine")
    public ResponseObject selectMerchantByIsExamine(){

        ArrayList<Merchant> merchantArrayList = adminService.selectMerchantByIsExamine();
        if (merchantArrayList.size()>0){
            return ResponseObject.success("查询成功",merchantArrayList);
        }else{
            return ResponseObject.success("数据为空");
        }
    }
    @RequestMapping("/selectMerchantById")
    public ResponseObject selectMerchantById(int id){
        ArrayList<Merchant> merchantArrayList = adminService.selectMerchantById(id);
        if (merchantArrayList.size()>0){
            return ResponseObject.success("查询成功",merchantArrayList);
        }else{
            return ResponseObject.success("数据为空");
        }
    }
    @RequestMapping("/updateMerchantIsExamine")
    public ResponseObject updateMerchantIsExamine(@RequestBody MerchantExamineDTO dto) {
        System.out.println(dto);
        System.out.println("接收到的商户数据：" + dto.toString());
        System.out.println(dto.getId());
        System.out.println(dto.getIsExamine());
        System.out.println("接收到的商户数据：" + dto.toString());
        System.out.println("接收到的商户数据：" + dto.toString());
        int result = adminService.updateMerchantIsExamine(dto.getId(), dto.getIsExamine(), dto.getRemark());
        if (result == 1) {
            return ResponseObject.success("更新成功");
        } else {
            return ResponseObject.success("更新失败");
        }
    }
}
